package com.baizhi.config;

import com.baizhi.interceptor.MyInterceptor;
import com.baizhi.interceptor.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 配置拦截器相关方法
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor())    // 指定拦截器
                .addPathPatterns("/**")                 // 拦截路径
                .excludePathPatterns("/file/**")        // 排除路径
                .order(1);  // 指定拦截器执行顺序，数字小的先执行，数字相同按配置顺序执行

        registry.addInterceptor(new MyInterceptor2())
                .addPathPatterns("/**")
                .excludePathPatterns("/file/**")
                .order(2);
    }
}
